<?php

	// +----------------------------------------------------------------------
	// | 商家EVENT
	// +----------------------------------------------------------------------
	// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
	// +----------------------------------------------------------------------
	// | Author: 微尘 <yicmf@qq.com>
	// +----------------------------------------------------------------------

	namespace app\event\store;

	use app\event\ucenter\User as UserUcenter;
	use app\model\ucenter\User as UserModel;
	use app\model\store\Store as StoreModel;
	use think\Exception;

	class User extends UserUcenter
	{

		/**
		 * @var UserModel
		 */
		protected $user;

		/**
		 * @param array $param
		 * @param UserModel $user
		 * @throws Exception
		 */
		public static function moduleAccessCheck($user,$param)
		{
//			$store = $user->store()->find();
//			if (!$store) {
//				throw new Exception('请先申请开通商铺功能');
//			}
		}


		/**
		 * 超管登录
		 * @param StoreModel $store
		 * @return array
		 */
		public function adminLogin($store)
		{
			try {
				$user = $store->user()->find();
				if (1 !== $user['status']) {
					throw new Exception('用户被禁用！');
				}

				$this->_saveSession($user,'store');
				/* 返回用户对象 */
				$data['code'] = 0;
				$data['data'] = $user;
				$data['message'] = '登录成功';
			} catch (Exception $e) {
				$data['code'] = 1;
				$data['message'] = $e->getMessage();
			}
			return $data;
		}
	}
